\documentclass[UTF8,no-math,12pt,openany,table,dvipsnames,svgnames]{article}
\usepackage{indentfirst}
\usepackage[fontset=none]{ctex}
\setCJKmainfont[BoldFont={FZHei-B01},ItalicFont={FZKai-Z03}]{FZShuSong-Z01}
\setCJKsansfont{FZHei-B01}
\setCJKfamilyfont{zhsong}{FZShuSong-Z01}
\setCJKfamilyfont{zhhei}{FZHei-B01}
\setCJKfamilyfont{zhkai}{FZKai-Z03}
\setCJKfamilyfont{zhfs}{FZFangSong-Z02}
\setCJKfamilyfont{zhli}{FZLiShu-S01}

\newcommand*{\songti}{\CJKfamily{zhsong}} % 宋体
\newcommand*{\heiti}{\CJKfamily{zhhei}} % 黑体
\newcommand*{\kaiti}{\CJKfamily{zhkai}} % 楷体
\newcommand*{\fangsong}{\CJKfamily{zhfs}} % 仿宋
\newcommand*{\lishu}{\CJKfamily{zhli}}    % 隶书
\usepackage{amsmath,amssymb,mathrsfs}
\usepackage[centering,
           top=2.54cm,bottom=2.54cm,right=2.9cm,left=2.9cm,
           headsep=25pt,headheight=20pt]{geometry}
\usepackage{newtxtext}
\usepackage{tcolorbox}
\tcbuselibrary{listings,breakable}
\tcbset{boxrule=0pt,sharp corners}
\usepackage[hyperindex]{hyperref}
\hypersetup{bookmarksopen=true,bookmarksopenlevel=1,bookmarksnumbered=true,
  pdftitle={行间公式的编号技巧},pdfauthor={向禹},linktoc=page,
  colorlinks,linkcolor=blue,citecolor=red,urlcolor=blue,anchorcolor=green}
\definecolor{structurecolor}{RGB}{0,120,2}%
\definecolor{winered}{rgb}{0.5,0,0}
\renewcommand{\ttdefault}{cmtt}
\lstdefinestyle{mystyle}{
  basicstyle=%
    \ttfamily
    \lst@ifdisplaystyle\small\fi
}

\lstset{basicstyle=\ttfamily,style=mystyle}

\definecolor{lightgrey}{rgb}{0.9,0.9,0.9}
\definecolor{frenchplum}{RGB}{190,20,83}
\lstset{language=[LaTeX]TeX,
	texcsstyle=*\color{winered},
	numbers=none,
	breaklines=true,
	keywordstyle=\color{winered},
	commentstyle=\color{gray},
	emph={fontenc,fontspec,xeCJK,FiraMono,xunicode,newtxmath,figure,fig,image,img,table,itemize,enumerate,newtxtext,newtxtt,ctex,microtype,description,times,newtx,booktabs,tabular,PDFLaTeX,XeLaTeX,type1cm,BibTeX,device,color,mode,lang,amsthm,tcolorbox,titlestyle,cite,marginnote,ctex,listings},
	emphstyle={\color{frenchplum}},
	morekeywords={DeclareSymbolFont,SetSymbolFont,toprule,midrule,bottomrule,institute,version,includegraphics,setmainfont,setsansfont,setmonofont ,setCJKmainfont,setCJKsansfont,setCJKmonofont,RequirePackage,figref,tabref,email,maketitle,keywords,definecolor,extrainfo,logo,cover,subtitle,appendix,chapter,hypersetup,mainmatter,tableofcontents,elegantpar,numbers,authoryear,heiti,kaishu,lstset,pagecolor,zhnumber,marginpar,part,equote},
	frame=single,
	tabsize=2,
	rulecolor=\color{structurecolor},
	framerule=0pt,
	columns=flexible,
	% backgroundcolor=\color{lightgrey}
}
\numberwithin{equation}{section}
\usepackage{cases,empheq}
\begin{document}
\title{多行公式的编号技巧}\date{\empty}
\maketitle
\href{https://yuxtech.github.io/tex/amsmath.pdf}{amsmath包} 对于行间公式的输出提供了非常强大的功能,我们今天则是介绍基于\textbf{amsmath}包如何去实现特定的多行公式编号技巧.

\section{多行公式一个编号}
在换行的公式中,如果直接用\textbf{align}环境会给每行都编号, \textbf{align*}环境则每一行都没有编号.但是我们可以用\verb|\notag|命令指定某些行不编号,如
\begin{tcblisting}{sidebyside}
\begin{align}
a&=b+c\notag\\
a^2&=b^2+c^2\\
a^3&=b^3+c^3\notag
\end{align}
\end{tcblisting}
除了用\textbf{align}环境之外,我们还可以用次环境\textbf{aligned}来更好地实现这种效果
\begin{tcblisting}{sidebyside}
\begin{align}\begin{aligned}
a&=b+c\\
a^2&=b^2+c^2
\end{aligned}\end{align}
\end{tcblisting}
\textbf{aligned}环境可以看成一个盒子,我们还可以给这个盒子添加定界符
\begin{tcblisting}{sidebyside}
\begin{align}
\left\{\begin{aligned}
&a=b+c\\
&a^2=b^2+c^2
\end{aligned}\right.\end{align}
\end{tcblisting}
指定不同块按等号对齐,同时每个区块一个编号,这时用\textbf{split}次环境
\begin{tcblisting}{sidebyside}
\begin{align}
a+b&=b+c\\
\begin{split}
a&=b+c\\
a^2&=b^2+c^2
\end{split}\\
\begin{split}
a&=b+c\\
a^2&=b^2+c^2
\end{split}
\end{align}
\end{tcblisting}
一行两个公式两个编号,这种情况自然需要\textbf{minipage}环境支持了.
\begin{tcblisting}{}
\begin{minipage}{0.5\textwidth}
\begin{equation}
a^2+b^2=c^2
\end{equation}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{equation}
a^3=b^3+c^3
\end{equation}
\end{minipage}
\end{tcblisting}
给带定界符的方程组的每一行都编号,这种情况\textbf{amsmath}包无法实现,我们可以用\textbf{cases}包的\textbf{numcases}环境
\begin{tcblisting}{sidebyside}
%\usepackage{cases}
\begin{numcases}{f(x)=}%f(x)=可以置空
1,&$x\in\mathbb Q$\\
0,&$x\notin\mathbb Q$
\end{numcases}.
\end{tcblisting}
不过上述\textbf{numcases}环境的效果是不尽如人意的,更好的效果是用\textbf{empheq}包,它可以给\textbf{amsmath}包提供的数学环境添加各种定界符.
\begin{tcblisting}{sidebyside}
\begin{empheq}[left=\empheqlbrace,right=\empheqrbrack]{align}
&a=b+c&&a=b\\
&a^2=b^2+c^2&&a=b
\end{empheq}
\end{tcblisting}
\end{document}